<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .login-container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 400px;
            padding: 40px 30px;
            backdrop-filter: blur(10px);
            transition: transform 0.3s ease;
        }

        .login-container:hover {
            transform: translateY(-5px);
        }

        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .login-header h1 {
            color: #333;
            font-size: 28px;
            margin-bottom: 10px;
        }

        .login-header p {
            color: #666;
            font-size: 16px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #444;
            font-weight: 500;
        }

        .form-group input {
            width: 100%;
            padding: 14px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        .form-group input:focus {
            border-color: #667eea;
            outline: none;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
        }

        .login-btn {
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 8px;
            color: white;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .login-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }

        .login-btn:active {
            transform: translateY(0);
        }

        .login-info {
            display: none;
            background: #f8f9fa;
            border-radius: 10px;
            padding: 25px;
            margin-top: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }

        .info-header {
            text-align: center;
            margin-bottom: 20px;
        }

        .info-header h2 {
            color: #333;
            font-size: 24px;
        }

        .info-item {
            display: flex;
            justify-content: space-between;
            padding: 12px 0;
            border-bottom: 1px solid #eee;
        }

        .info-item:last-child {
            border-bottom: none;
        }

        .info-label {
            font-weight: 500;
            color: #555;
        }

        .info-value {
            color: #333;
            font-weight: 600;
        }

        .logout-btn {
            display: block;
            width: 100%;
            padding: 12px;
            margin-top: 20px;
            background: #eee;
            border: none;
            border-radius: 8px;
            color: #333;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.3s;
        }

        .logout-btn:hover {
            background: #ddd;
        }

        .error-message {
            color: #e74c3c;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
    </style>
</head>
<body>
<div class="login-container" id="loginContainer">
    <div class="login-header">
        <h1>用户登录</h1>
        <p>请输入您的账号信息</p>
    </div>

    <form id="loginForm">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" placeholder="请输入用户名" required>
            <div class="error-message" id="usernameError">请输入用户名</div>
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" placeholder="请输入密码" required>
            <div class="error-message" id="passwordError">请输入密码</div>
        </div>

        <button type="submit" class="login-btn">登录</button>
    </form>

    <div class="login-info" id="loginInfo">
        <div class="info-header">
            <h2>登录信息</h2>
        </div>

        <div class="info-item">
            <span class="info-label">用户名:</span>
            <span class="info-value" id="displayUsername"></span>
        </div>

        <div class="info-item">
            <span class="info-label">登录时间:</span>
            <span class="info-value" id="loginTime"></span>
        </div>

        <div class="info-item">
            <span class="info-label">会话时长:</span>
            <span class="info-value" id="sessionDuration">0秒</span>
        </div>

        <div class="info-item">
            <span class="info-label">登录IP:</span>
            <span class="info-value" id="loginIP">192.168.1.100</span>
        </div>

        <div class="info-item">
            <span class="info-label">登录设备:</span>
            <span class="info-value" id="loginDevice">Windows 10 / Chrome</span>
        </div>

        <button class="logout-btn" id="logoutBtn">退出登录</button>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const loginForm = document.getElementById('loginForm');
        const loginContainer = document.getElementById('loginContainer');
        const loginInfo = document.getElementById('loginInfo');
        const logoutBtn = document.getElementById('logoutBtn');
        const usernameInput = document.getElementById('username');
        const passwordInput = document.getElementById('password');
        const displayUsername = document.getElementById('displayUsername');
        const loginTime = document.getElementById('loginTime');
        const sessionDuration = document.getElementById('sessionDuration');
        const usernameError = document.getElementById('usernameError');
        const passwordError = document.getElementById('passwordError');

        let loginTimestamp = null;
        let sessionTimer = null;

        // 格式化时间
        function formatTime(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }

        // 更新会话时长
        function updateSessionDuration() {
            if (loginTimestamp) {
                const now = new Date();
                const diff = Math.floor((now - loginTimestamp) / 1000);
                const hours = Math.floor(diff / 3600);
                const minutes = Math.floor((diff % 3600) / 60);
                const seconds = diff % 60;

                if (hours > 0) {
                    sessionDuration.textContent = `${hours}小时${minutes}分钟${seconds}秒`;
                } else if (minutes > 0) {
                    sessionDuration.textContent = `${minutes}分钟${seconds}秒`;
                } else {
                    sessionDuration.textContent = `${seconds}秒`;
                }
            }
        }

        // 登录处理
        loginForm.addEventListener('submit', function(e) {
            e.preventDefault();

            const username = usernameInput.value.trim();
            const password = passwordInput.value;

            // 重置错误信息
            usernameError.style.display = 'none';
            passwordError.style.display = 'none';

            let hasError = false;

            // 验证用户名
            if (!username) {
                usernameError.style.display = 'block';
                hasError = true;
            }

            // 验证密码
            if (!password) {
                passwordError.style.display = 'block';
                hasError = true;
            }

            if (hasError) return;

            // 虚假登录验证（总是成功）
            loginTimestamp = new Date();

            // 显示登录信息
            displayUsername.textContent = username;
            loginTime.textContent = formatTime(loginTimestamp);
            updateSessionDuration();

            // 开始计时器更新会话时长
            sessionTimer = setInterval(updateSessionDuration, 1000);

            // 切换显示
            loginForm.style.display = 'none';
            loginInfo.style.display = 'block';
        });

        // 退出登录
        logoutBtn.addEventListener('click', function() {
            // 清除定时器
            if (sessionTimer) {
                clearInterval(sessionTimer);
            }

            // 重置表单
            loginForm.reset();

            // 切换显示
            loginForm.style.display = 'block';
            loginInfo.style.display = 'none';
        });

        // 模拟设备检测
        function detectDevice() {
            const userAgent = navigator.userAgent;
            let os = "未知操作系统";
            let browser = "未知浏览器";

            // 检测操作系统
            if (userAgent.includes("Windows NT 10")) os = "Windows 10";
            else if (userAgent.includes("Windows NT 6.3")) os = "Windows 8.1";
            else if (userAgent.includes("Windows NT 6.2")) os = "Windows 8";
            else if (userAgent.includes("Windows NT 6.1")) os = "Windows 7";
            else if (userAgent.includes("Mac")) os = "MacOS";
            else if (userAgent.includes("Linux")) os = "Linux";
            else if (userAgent.includes("Android")) os = "Android";
            else if (userAgent.includes("iPhone")) os = "iOS";

            // 检测浏览器
            if (userAgent.includes("Chrome") && !userAgent.includes("Edg")) browser = "Chrome";
            else if (userAgent.includes("Firefox")) browser = "Firefox";
            else if (userAgent.includes("Safari") && !userAgent.includes("Chrome")) browser = "Safari";
            else if (userAgent.includes("Edg")) browser = "Edge";
            else if (userAgent.includes("Opera") || userAgent.includes("OPR")) browser = "Opera";

            document.getElementById('loginDevice').textContent = `${os} / ${browser}`;
        }

        // 初始化设备检测
        detectDevice();
    });
</script>
</body>
</html>